#ifndef __ABLIST_H__
#define __ABLIST_H__

#include <stdio.h>
#include <time.h>
#include <pthread.h>

typedef enum ab_list_item_status
{
    AB_ITEM_STATUS_NOT_USED = 0,
    AB_ITEM_STATUS_USED,
    AB_ITEM_STATIS_BUTT
}en_ab_item_status;

#define AB_LIST_ITEM_MAGIC (0x3E8F7B89)
typedef struct ab_list_item
{
    unsigned int magic;
    en_ab_item_status status;
    unsigned int len[2];
    unsigned char *pdata[2];
    struct ab_list_item *next;
    unsigned int actual_size;/* whole item actual size,think of aligned and item itself size */
}st_ab_list_item;

typedef struct ab_dynamic_list
{
    unsigned int volume; // total buffer size,bytes
    unsigned int freesize; // available buffer size to write, bytes
    unsigned int nread; // available count number to read from buffer
    st_ab_list_item *phead;
    st_ab_list_item *pread;
    st_ab_list_item *pwrite;
    pthread_rwlock_t rwlock;
}st_ab_dynamic_list;

st_ab_dynamic_list *ab_init_list(unsigned char *list_buf,unsigned int volume);
void ab_exit_list(st_ab_dynamic_list *list);
int ab_read_item_data(st_ab_dynamic_list *list,unsigned char *buf,int len);
int ab_write_item_data(st_ab_dynamic_list *list,unsigned char *header,int hlen,unsigned char *data,int dlen);

#endif

